﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Recycle.ascx.cs" Inherits="FreshCms.BackEnd.Controls.Product.Recycle" %>
<%@ Register Src="~/BackEnd/ControlsCommon/Pager.ascx" TagName="Pager" TagPrefix="uc" %>

<script src="/BackEnd/js/jquery.price_format.min.js" type="text/javascript"></script>

<div id="page-content" class="block">
    <div class="block-header">
        <a href="javascript:void(0)" class="header-title-link">
            <h1>Quản lý sản phẩm lưu trữ</h1>
        </a>
    </div>

    <div class="col-sm-2"></div>
    <div class="col-sm-9">
        <div class="block">
            <div class="block-title"><h2>Chức năng</h2></div>
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-gift"></i></span>
                            <input type="text" id="txtProName" class="form-control" value="<%=name %>">
                            <span class="input-group-addon">Tên sản phẩm</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-sitemap"></i></span>
                            <asp:DropDownList ID="ddlCate" runat="server" CssClass="form-control" size="1"></asp:DropDownList>
                            <span class="input-group-addon">Danh mục</span>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-barcode"></i></span>
                            <input type="text" id="txtProCode" class="form-control" value="<%=code %>">
                            <span class="input-group-addon">Mã sản phẩm</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group text-center">
                <button type="button" id="btnSearch" class="btn btn-sm btn-info"><i class="gi gi-search mr5"></i>Tìm kiếm</button>
                <a href="/BackEnd/?ui=11" id="btnAdd" class="btn btn-sm btn-success"><i class="hi hi-plus mr5"></i>Thêm mới</a>
            </div>
        </div>
    </div>

    <div class="table-responsive">
        <table id="tblParent" class="table table-hover">
            <thead>
                <tr>
                    <th class="text-center" style="width: 60px;">#</th>
                    <th class="text-center" style="width: 60px;">Id</th>
                    <th>Tên sản phẩm</th>
                    <th style="width: 120px;">Mã</th>
                    <th style="width: 100px;">Giá</th>
                    <th class="text-center" style="width: 150px;">Thao tác</th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rpt" runat="server">
                    <ItemTemplate>
                        <tr id="trMain_<%# Eval("ProId") %>">
                            <td class="text-center"><%# Container.ItemIndex + 1 %></td>
                            <td class="text-center"><%# Eval("ProId")%></td>
                            <td>
                                <span class="data-title"><%# Eval("ProName")%></span>
                                <span class="data-author">(người tạo: <b><%# Eval("UserMail")%></b>)</span>
                                
                            </td>
                            <td><%# Eval("ProCode")%></td>
                            <td rel="tdPrice"><%# Eval("ProNewPrice")%></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a href="/BackEnd/?ui=11&id=<%# Eval("ProId") %>" data-toggle="tooltip" title="" class="btn btn-xs btn-default"
                                        data-original-title="Xem chi tiết"><i class="gi gi-eye_open"></i></a>
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default btn-success" onclick="RecoverData(<%# Eval("ProId") %>, '<%#Server.HtmlEncode(Eval("ProName").ToString())%>')"
                                        data-original-title="Phục hồi"><i class="gi gi-restart"></i></a>
                                    <div class="btn-group dropup text-left">
                                        <a href="javascript:void(0)" data-toggle="dropdown" class="btn btn-xs btn-default btn-danger dropdown-toggle"><i class="gi gi-remove_2"></i> </a>
                                        <ul class="dropdown-menu dropdown-menu-delete">
                                            <li><a href="javascript:void(0)" onclick="DeleteData(<%# Eval("ProId") %>, '<%#Server.HtmlEncode(Eval("ProName").ToString())%>')" data-toggle="tooltip" data-original-title="Sản phẩm xóa vĩnh viễn sẽ không thể phục hồi" data-placement="left">Xóa vĩnh viễn</a></li>
                                            <li><a href="javascript:void(0)">Hủy</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
    </div>
    <div class="text-center">
        <uc:Pager ID="Pager" runat="server" />
    </div>
</div>

<script>
    $(function () {
        // format tiền cho cả list
        $("#tblParent td[rel*='tdPrice']").each(function () {
            $(this).priceFormat({
                prefix: '',
                centsSeparator: ',',
                thousandsSeparator: '.',
                centsLimit: 0
            });
        });
    });

    $("#btnSearch").bind("click", function () {
        var link = '/BackEnd/?ui=<%=panelId %>';
        
        if ($('#txtProName').val().length > 0) link = link + '&name=' + $('#txtProName').val();
        link = link + '&cate=' + $('#<%=ddlCate.ClientID %>').val();
        if ($('#txtProCode').val().length > 0) link = link + '&code=' + $('#txtProCode').val();
        
        window.location.href = link;
    });

    
    // event Recover Fast in data table
    function RecoverData(id, proname) {
        // call ajax
        var param;
        param = {
            m: "recover",
            ui : <%=panelId %>,
            id: id,
            name: proname
        };
        $.ajax({
            url: "/BackEnd/Handler/Product.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Phục hồi sản phẩm thành công, sản phẩm này sẽ có trạng thái [Khóa] ở trang <a href="/BackEnd/?ui=12">[Quản Lý]</a>', 'reload', false);
                }
                else {
                    jWaiting.callWaitingMessError(data.Message);
                }
            }
        });
    }

    // event Delete Fast in data table
    function DeleteData(id, proname) {
        // call ajax
        var param;
        param = {
            m: "delete",
            ui : <%=panelId %>,
            id: id,
            name: proname
        };
        $.ajax({
            url: "/BackEnd/Handler/Product.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Xóa vĩnh viễn sản phẩm thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError(data.Message);
                }
            }
        });
    }
</script>